Python | Pandas Index.hasnans
Below, are the examples of Python | Pandas Index.hasnans in Python.
Example 1: Index Creation with Pandas
Use Index.hasnans
attribute to check if there is any missing value in the given Index object.
# importing pandas as pd
import pandas as pd
# Creating the index
idx = pd.Index(['Jan', 'Feb', 'Mar', 'Apr', 'May'])
# Print the index
print(idx)
Output
Index(['Jan', 'Feb', 'Mar', 'Apr', 'May'], dtype='object')
Now we will use Index.hasnans
attribute to check if there is any missing value in the given Index object.
# check if there is any
# missing value
result = idx.hasnans
# Print the result
print(result)
Output
False
As we can see in the output, the Index.hasnans
attribute has returned False
indicating there is no missing value in the given Index object.
Example 2 : Creating Date Index with Pandas
Use Index.hasnans
attribute to check if there is any missing value in the given Index object.
# importing pandas as pd
import pandas as pd
# Creating the index
idx = pd.Index(['2012-12-12', None, '2002-1-10', None])
# Print the index
print(idx)
Output :
Index(['2012-12-12', None, '2002-1-10', None], dtype='object')
Now we will use Index.hasnans
attribute to check if there is any missing value in the given Index object.
# check if there is any
# missing value
result = idx.hasnans
# Print the result
print(result)
Output
True
As we can see in the output, the Index.hasnans
attribute has returned True
indicating there is some missing values in the given Index object.
Python | Pandas Index.hasnans
Pandas Index is an immutable ndarray implementing an ordered, sliceable set. It is the basic object that stores the axis labels for all panda’s objects. Pandas Index.hasnans
attribute return True
if there is any missing value in the given Index object otherwise it returns False
indicating there are no missing values in the given Index object
Syntax: Index.hasnans
Parameter : None
Returns : boolean